#!/bin/bash
#

function check_memcached() {
    netstat -tunlp | grep memcached &> /dev/null 
    REVTAL=$?
    
    if [ $REVTAL -eq 0 ]; then 
        memcached_pid=`netstat -tunlp | grep memcached | awk '{print $NF}' | awk -F '/' '{print $1}'`
        echo "$(date +%Y-%m-%d" "%H:%M:%S) - - memcached service is running: ${memcached_pid}."
    else
        /usr/local/memcached-1.5.16/bin/memcached -c 500000 -m 24000 -d -u memcached -l 127.0.0.1 -P 11211 -U 0 -t 12
    fi
}


while true; do
    check_memcached
    sleep 60s
done